/**
 * 初始化质控-数据源详情对话框
 */
var SdcQcRuleDatasourceInfoDlg = {
    validateFields: {
        code: {
            validators: {
                notEmpty: {
                    message: '代码不能为空'
                }
            }
        },
    	dataSource: {
            validators: {
                notEmpty: {
                    message: '数据源不能为空'
                }
            }
        },
    	dataSourceItem: {
            validators: {
                notEmpty: {
                    message: '具体取值项目不能为空'
                }
            }
        },
    }
};


/**
 * 关闭此对话框
 */
SdcQcRuleDatasourceInfoDlg.close = function() {
    parent.layer.close(parent.layer.getFrameIndex(window.name)); //先得到当前iframe层的索引,再执行关闭   
}

/**
 * 验证数据是否为空
 */
SdcQcRuleDatasourceInfoDlg.validate = function () {
    $('#sdcQcRuleDatasourceInfoForm').data("bootstrapValidator").resetForm();
    $('#sdcQcRuleDatasourceInfoForm').bootstrapValidator('validate');
    return $("#sdcQcRuleDatasourceInfoForm").data('bootstrapValidator').isValid();
}

/**
 * 提交新增
 */
SdcQcRuleDatasourceInfoDlg.addSubmit = function() {

    if (!this.validate()) {
        return;
    }
    //提交信息
    Sys.ajaxForm('sdcQcRuleDatasourceInfoForm',Sys.backendPath + "/sdc/sdcqcconfig/addRuleSource",function(res) {
        Sys.success(res.message);
        window.parent.obj.qCRuleChange();
        SdcQcRuleDatasourceInfoDlg.close();
    });
}

/**
 * 提交修改
 */
SdcQcRuleDatasourceInfoDlg.editSubmit = function() {

    if (!this.validate()) {
        return;
    }
    //提交信息
    Sys.ajaxForm('sdcQcRuleDatasourceInfoForm',Sys.backendPath + "/sdc/sdcqcconfig/updateRuleSource",function(res) {
        Sys.success(res.message);
        window.parent.obj.qCRuleChange();
        SdcQcRuleDatasourceInfoDlg.close();
    });
}

$(function() {
	Sys.initValidator("sdcQcRuleDatasourceInfoForm", SdcQcRuleDatasourceInfoDlg.validateFields);
});
